# coding=utf-8

from datetime import datetime
from app.cls import database
from app.cls import log_manager
from flask_login import UserMixin
from werkzeug.security import check_password_hash

class Users(database.Document, UserMixin):
    """Users' class

    Base on mongoengine's class and Flask_login UserMixin,
    UserMixin to suit Flask_login.

    Attributes:
        Id
        Name
        Password_hash : hash power by werkzeug.security
        Room_Id : The member belongs to the room.this room's Id.
        Notice_list (dict class {'date' : 'Id'} )

    Functions:
        check_password() : Check the password
            Args:
                password : will be checked
    """

    Id = database.IntField(required=True)
    Name = database.StringField(required=True)
    Password_hash = database.StringField(required=True)
    Room_Id = database.IntField()
    Notice_list = database.ListField()

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)


class Room(database.Document):
    """Rooms' class

    Base on mongoengine's class.

    Attributes:
        Id
        Name
        Introduction
        Number_list (list class)

    """

    Id = database.IntField(required=True)
    Name = database.StringField(required=True)
    Introduction = database.StringField(required=True)
    Number_list = database.ListField(database.IntField())

class Notice(database.Document):
    """Notices' class

    Base on mongoengine's class.

    Attributes:
        Id
        User_Id : The Notice belongs to user whose Id.
        Date
        Content
    """

    Id = database.IntField(required=True)
    User_Id = database.IntField(required=True)
    Date = database.IntField(required=True)
    Content = database.StringField(required=True)

@log_manager.user_loader
def load_user(user_id):
    return Users.objects(Id=user_id).first()
